package com.example.littleSpider.myapplication.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.littlespider.mylibrary.util.Print;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by abc on 2017/9/5.
 */
public abstract class BaseActivity extends AppCompatActivity {
    Unbinder unbinder;
    private Toast toast;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Print.i("className"+  getClass().toString());
        setContentView(getLayoutRes());
        unbinder = ButterKnife.bind(this);
        initView();
        initData();
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        //解除Activity对ButterKnife的绑定
        unbinder.unbind();
    }
    /**
     * 返回布局文件
     * @return
     */
    protected abstract int getLayoutRes();
    /**
     * 初始化控件
     */
    protected abstract void initView();
    /**
     * 初始化本界面中要用到的数据
     */
    protected abstract void initData();
    /**
     * 弹出吐司并防止重复弹出的方法
     * @param content 吐司里要显示的内容
     */
    protected void Tshow(String content){
        if (toast != null){
            toast.cancel();
        }
        toast = Toast.makeText(this, content, Toast.LENGTH_SHORT);
        toast.show();
    }
}
